const jsLogin = require('./main/js_login');
const login = require('./main/merchant_login');
const Junglescout = require('./main/junglescout_login');
const request    = require('request');
const jsplugin = require('./valid/js_plugin');
const elves    = require('./valid/elves');
const elvesLogin = require('./main/elves_login');
const crypto    = require('crypto');
const elvesPluginLogin = require('./main/elves_plugin_login');
const elvesPluginValid = require('./valid/elves_plugin');
const heliumLogin = require('./main/helium_login');
const heliumValid = require('./valid/helium');
const merchantValid = require('./valid/merchant_word');

async function ttt() {
    let a = new jsLogin('inn672@163.com','mmnn123456');
    let cookies = await a.do();
    console.log(`cookies: ${JSON.stringify(cookies)}`)
}

async function yyy() {
    let a = new login('uwu252@163.com','nbzw1260');
    let s = await a.do().then((res) => {
        res = res.replace(/[\r\n]/g,"")
        console.log(`merchant login finish... cookies:${res}`)
    }).catch((e) => {
        console.log(`merchant login failed...`)
    });

}

async function iii() {
    let a = new Junglescout('uki058@163.com','asdf1234..');
    await a.do();
}

async function ooo() {
    let options = {
        url:'https://www.merchantwords.com/search/us/lv/sort-highest'
    }
}

async function requestTest() {
    let options = {
        url:'https://xiaomingblog.cn/prod-api/client-product-users/23',
        method:'get',
        headers:{
            'authorization':'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2lkIjoibG9naW5fdG9rZW5zOkNMSUVOVF9VU0VSOjkyYzRhZjdjLWY2MzMtNDdiNy1iN2VhLWYzNTI4MTI1Y2QyOSIsImxvZ2luX3VzZXJfdXVpZF9rZXkiOiI5MmM0YWY3Yy1mNjMzLTQ3YjctYjdlYS1mMzUyODEyNWNkMjkifQ.wLlcz--ZU088_YyId8Cb1KAOLaLoe879fl3yCW6oQ5BNME-R_usXdXh6muqYKgFMVmzBb7j3R27ZxF0FqfXvkQ',
            'version':'0.1.2',
            'x-user-system-id':'CLIENT_USER'
        }
    }
    request(options,async (err,response,body) => {
        if(err){
            console.log(`失败:${JSON.stringify(err)}`);
        }else{
            console.log(JSON.stringify(body))
        }
    })
}
async function testJsPlugin() {
    let cookie = 'Bearer ZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKbGVIQWlPakUyTWpFMk5EZzNOellzSW1saGRDSTZNVFl4T1RBMU5qYzNOaXdpYVhOeklqb2lhblZ1WjJ4bGMyTnZkWFJmWVhCcFgyVjRkR1Z1YzJsdmJpSXNJbUYxWkNJNkltTnNhV1Z1ZENJc0ltRjFkR2hmZEc5clpXNGlPaUkzTXpFMk1HSmxPV1F5TURRMk0yWTFZalV4WldSbE16ZGtNR0U1WlRZMU15SjkuVlViZlhvcUl6R1FmYlBRUTVPTHJiYTBFSUp6dGV4QXI4SnMzdXl6Qmhrcw==';
    let js = new jsplugin();
    let status = await js.validCookie(cookie);
    console.log(`Status:${status}`)
}

async function testElves() {
    let cookie = 'rank-login-user=9700330261IrZXNTSoIlHhPKyHGfg/7TMbw6xY7YpCjminsqgfQO27D+NGb9VvGdhKEKXQPMwv;ao_lo_to_n="9700330261IrZXNTSoIlHhPKyHGfg/7Yru76q6n4vo7TvQW2uhQJdq9I9h7MsV0BM3wcSRr2hdVhozAhpiwtIA++dNAXa65Q9j7/+vnlBx+6nVPiz2fqg=";';
    let el = new elves();
    let valid = await el.valid(cookie);
    console.log(`Status:${valid}`)
}

async function testElvesLogin() {
    let username = '1619723678@qq.com';
    let password = 'qwer1234..';
    let s = new elvesLogin(username,password);
    await s.do();
}

async function testMD5() {
    let password = 'qwer1234..';
    let username = '1619723678@qq.com';
    var result = crypto.createHash('md5').update(password).digest("hex");
    var slat = crypto.createHash('md5').update((username + result).toString()).digest("hex");
    console.log(`password:${result}`);
    console.log(`slat:${slat}`);
}

async function testElvesPluginLogin() {
    let username = '1619723678@qq.com';
    let password = 'qwer1234..';

    let s = new elvesPluginLogin(username,password);
    let result = await s.do();
}

async function testElvesPluginValid() {
    let cookie = '6816219161IrZXNTSoIlHhPKyHGfg/7TMbw6xY7YpCjminsqgfQO1dkZrIeuscHGFZYEbFpD1J';
    let s = new elvesPluginValid();
    let result = await s.validCookie(cookie);
    console.log(`valid:${result}`)
}

async function testHeliumLogin() {
    let username = 'xiaoming6379@gmail.com';
    let password = 'chen19960119';
    let s = new heliumLogin(username,password);
    let cookies = await s.do();
    console.log(`${cookies}`)
}

async function testHeliumValid() {
    let cookie = '_gcl_au=1.1.1643416236.1619421001; _ga=GA1.2.549444868.1619421001; _fbp=fb.1.1619421001215.1012813853; _vis_opt_s=1%7C; _vis_opt_test_cookie=1; _ga=GA1.3.549444868.1619421001; _pin_unauth=dWlkPU1HVTNPR1ZoTldFdFpUUmlZaTAwTXpRMUxUa3lNakV0TTJJNFpqUTJNemxsWW1OaQ; _pin_unauth=dWlkPU1HVTNPR1ZoTldFdFpUUmlZaTAwTXpRMUxUa3lNakV0TTJJNFpqUTJNemxsWW1OaQ; current-marketplace=5a7deede86e62213f2adae2c21dde37c8919c5317898e27c859a9080214c380fa%3A2%3A%7Bi%3A0%3Bs%3A19%3A%22current-marketplace%22%3Bi%3A1%3Bs%3A13%3A%22ATVPDKIKX0DER%22%3B%7D; ab.storage.deviceId.4d3ca359-c724-43de-9b97-cb9f1fee4769=%7B%22g%22%3A%22f69f243b-4cb0-2dd5-b1b4-0c1738016d8a%22%2C%22c%22%3A1619507200786%2C%22l%22%3A1619507200786%7D; amplitude_idundefinedhelium10.com=eyJvcHRPdXQiOmZhbHNlLCJzZXNzaW9uSWQiOm51bGwsImxhc3RFdmVudFRpbWUiOm51bGwsImV2ZW50SWQiOjAsImlkZW50aWZ5SWQiOjAsInNlcXVlbmNlTnVtYmVyIjowfQ==; GleamId=OQXWza%7BV%3A%3C%2CY2%3CCxM; sidebar=10e72d2c5fa6bd03252eaf0d9f87e2bc1020bb80d5d174d7a4a3ed09e7a80426a%3A2%3A%7Bi%3A0%3Bs%3A7%3A%22sidebar%22%3Bi%3A1%3Bs%3A0%3A%22%22%3B%7D; _derived_epik=dj0yJnU9WDI2TVU2b0RvQVBlSGlXWGNyaHlEN2NNeXA1Wmp5cjgmbj1Mbl9jSGVlZTZIZHcyOWtJVHNtQmZBJm09NyZ0PUFBQUFBR0NLRmtrJnJtPTQmcnQ9QUFBQUFHQ0h1Znc; _gid=GA1.3.1973120119.1620617150; GleamA=%7B%22OQXWz%22%3A%22UserId%22%7D; __stripe_mid=4fd05e29-f65a-4769-8c08-ad4e6b524e98f028d7; _csrf=97e70572b4621a3a31d36b56085a207133e07acf5aa87ecb77dc38e07e806f79a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22N6mI_pEMpLAEIC6LLOBd4XSJzD1NmPIK%22%3B%7D; ab.storage.userId.4d3ca359-c724-43de-9b97-cb9f1fee4769=%7B%22g%22%3A%221544210556%22%2C%22c%22%3A1620637074989%2C%22l%22%3A1620637074989%7D; ajs_user_id=%221544210556%22; ajs_anonymous_id=%220edda04f-2ebc-468f-8033-6d5b12c2ceab%22; _derived_epik=dj0yJnU9bFFqd0tQVGJvRDluYTBNcHNLeXQ5LTJUN2FYUW9GZ2smbj1xc2VXZzU0aTNoYWZXRmc5R2xMRlNBJm09NyZ0PUFBQUFBR0NZOWtZJnJtPTQmcnQ9QUFBQUFHQ0h1Znc; intercom-session-yzizpoku=WEsyQTZaS0o0Zzl0dnY4V2lmTnV0NUtoSFYwUjJJUVU2VW1KTkFOQmJEek1sMmNvMnFITjBBc0M4dTkxZUJoVi0tMGE0TVN2ZkxpZnd1bVkxU0JNL3JOdz09--506881d27cf1e7e99060a3aec34639eec1126ae9; _identity=ebdb9724fc886de86bc63d4e3afb9d7fd73be50fc118c5e719437898331ced3ba%3A2%3A%7Bi%3A0%3Bs%3A9%3A%22_identity%22%3Bi%3A1%3Bs%3A81%3A%22%5B1544210556%2C%22mRR-IxRkGs7NIC_uR73EiB5Wn_wd8vqR%22%2C2592000%2Cnull%2Cnull%2C%22112.45.97.236%22%5D%22%3B%7D; video_106g57oln8_time=32.894887; video_106g57oln8_type=popover; dsik=53dd9a1e0e6b08edd64ab540e247306055b3c1ab368c1754e1a8aa251681807aa%3A2%3A%7Bi%3A0%3Bs%3A4%3A%22dsik%22%3Bi%3A1%3Bs%3A64%3A%22Ffy7dqTnwJxR3EYkJJUhoI9xNw_O0bTpblgDUEvhC5KMoL4s2_qCrtq_cUI-OLj8%22%3B%7D; sid=qrl7opccia4caotnkrd7483gmk; ab.storage.sessionId.4d3ca359-c724-43de-9b97-cb9f1fee4769=%7B%22g%22%3A%22f2bc7c89-c368-aa91-1434-784bc089d42f%22%2C%22e%22%3A1620718743323%2C%22c%22%3A1620716943323%2C%22l%22%3A1620716943323%7D; _dc_gtm_UA-75738827-2=1; _uetsid=6ad36890b13f11eb8f3cffc72df6516a; _uetvid=6a7df5d0a65e11ebafeebf199c37706e; amplitude_id_95d3abbefaf19863dc230d5449736018helium10.com=eyJkZXZpY2VJZCI6ImYyM2JlOTZlLThlMTktNDYwMC1hZjI3LTQ0NTQ4MWY2NjRjN1IiLCJ1c2VySWQiOiIxNTQ0MjEwNTU2Iiwib3B0T3V0IjpmYWxzZSwic2Vzc2lvbklkIjoxNjIwNzE2OTQzODE4LCJsYXN0RXZlbnRUaW1lIjoxNjIwNzE2OTQzODI5LCJldmVudElkIjozNywiaWRlbnRpZnlJZCI6NjgsInNlcXVlbmNlTnVtYmVyIjoxMDV9; AWSALB=MteOQ2UifPcAMRoUIXKbDrqynUhbC7VdC4W2xQSelfEv09BcPlIg/5ugMFy8UqHhEUFX3k0KepoWIrAQHcRqSGHEIpAn2JuEcPGmF7WEGNgGkSXPX0o8j9zptwsv; AWSALBCORS=MteOQ2UifPcAMRoUIXKbDrqynUhbC7VdC4W2xQSelfEv09BcPlIg/5ugMFy8UqHhEUFX3k0KepoWIrAQHcRqSGHEIpAn2JuEcPGmF7WEGNgGkSXPX0o8j9zptwsv; io=f9eVPHWQTRvFnQgACYEV';
    let s = new heliumValid();
    let result = await s.valid(cookie);
}

async function testMerchantValid(){
    let cookie = '_gat_https%3A%2F%2Fwww.merchantwords.com%2Femerging-trends=1;_gat_https%3A%2F%2Fwww.merchantwords.com%2Fsearch%2Fus%2Fled%2Fsort-highest=1;_gat_https%3A%2F%2Fwww.merchantwords.com%2Fmy-account=1;mvt1=1;ubId=xB60d96ae6uqQBD1_ubid;mp_1102b81d424da9270ca275eb2e01a038_mixpanel=%7B%22distinct_id%22%3A%20%22uwu252%40163.com%22%2C%22%24device_id%22%3A%20%2217a5147f36d1c8-09cbbe430726c8-594f2116-1fa400-17a5147f36ec50%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22__mps%22%3A%20%7B%7D%2C%22__mpso%22%3A%20%7B%7D%2C%22__mpus%22%3A%20%7B%7D%2C%22__mpa%22%3A%20%7B%7D%2C%22__mpu%22%3A%20%7B%7D%2C%22__mpr%22%3A%20%5B%5D%2C%22__mpap%22%3A%20%5B%5D%2C%22%24user_id%22%3A%20%22uwu252%40163.com%22%2C%22Email%22%3A%20%22uwu252%40163.com%22%2C%22ubid%22%3A%20%22xB60d96ae6uqQBD1_ubid%22%2C%22userId%22%3A%20%22Jw60d94395lb02C1_usr%22%7D;_gat=1;__zlcmid =14ok8esvPeOcSbI;_fbp=fb.1.1624861308096.1974858778;_gid=GA1.2.1079778922.1624861308;__cf_bm=bf330545a853e57940859666954c3bfd0766f74a-1624861304-1800-AVgrAD2d68Cw5gwwaUQ7FzjqXMA/cUvg+7scuqga3InVxCwjqWutdc3CRDLG8fpejIH3t6ohrpDTuND2RlZCL/ClJLTWt/5opkbcWKDNruDUonNHdrUp8U845oj8vTTskA==;_ga=GA1.2.829525408.1624861308;_gcl_au=1.1.183095266.1624861307;mwtranslate=us-led;JSESSIONID=QlmpP4MXAHhUuTmVtukR6A';
    let s = new merchantValid();
    let result = await s.valid(cookie);
    console.log(`result:${result}`)
}

async function parserCookiesByUbId(cookie){
    let cks = cookie.split(';');
    cks.some(function (value) {
        let vs = value.split('=');
        console.log(`vs:${JSON.stringify(vs)}`)
        if(vs[0].replace(' ','') === 'ubId'){
            console.log(vs[1]);
            return vs[1];
        }
    });
    return undefined;
}


testMerchantValid();
// yyy();
